package smedi.ismedi.web.bff.controller.dictionary;

import com.smedi.ismedi.dictionary.dto.response.DictionaryItemResponse;
import com.smedi.ismedi.dictionary.dto.response.DictionaryTypeResponse;
import com.smedi.ismedi.dictionary.dto.response.DictionaryTypeWithItemResponse;
import com.smedi.ismedi.dictionary.feign.RemoteDictionaryQueryFeignApi;
import com.smedi.ismedi.web.starter.common.PaginationData;
import com.smedi.ismedi.web.starter.common.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import smedi.ismedi.web.bff.controller.BaseController;

import java.util.List;

/**
 * @Author Jimmy
 * @Date 2021/6/2 10:16
 */
@Api(value = "数据字典查询", tags = {"数据字典查询"})
@RequestMapping(value = "/webbff/v1/dictionaryQuery")
@RestController
@AllArgsConstructor
public class DictionaryQueryController extends BaseController {
    private final RemoteDictionaryQueryFeignApi dictionaryQueryFeignApi;

    /**
     * 获取所有字典类型
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ApiOperation(value = "获取所有字典类型", nickname = "获取所有字典类型")
    @GetMapping(value = "/getAllDictionaryType")
    ResponseData<PaginationData> getAllDictionaryType(
            @ApiParam(value = "pageNum", required = true) @RequestParam(value = "pageNum", required = true) int pageNum,
            @ApiParam(value = "pageSize", required = true) @RequestParam(value = "pageSize", required = true) int pageSize) {
        return dictionaryQueryFeignApi.getAllDictionaryType(pageNum, pageSize);
    }

    /**
     * 根据Id查询字典项类型
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "根据Id查询字典项类型", nickname = "根据Id查询字典项类型")
    @GetMapping(value = "/getDictionaryTypeById")
    ResponseData<DictionaryTypeResponse> getDictionaryTypeById(@ApiParam(value = "id", required = true) @RequestParam(value = "id", required = true) Long id) {
        return dictionaryQueryFeignApi.getDictionaryTypeById(id);
    }

    /**
     * 根据Type查询字典项类型
     *
     * @param type
     * @return
     */
    @ApiOperation(value = "根据Type查询字典项类型", nickname = "根据Type查询字典项类型")
    @GetMapping(value = "/getDictionaryTypeByType")
    ResponseData<DictionaryTypeResponse> getDictionaryTypeByType(@ApiParam(value = "type", required = true) @RequestParam(value = "type", required = true) String type) {
        return dictionaryQueryFeignApi.getDictionaryTypeByType(type);
    }

    /**
     * 根据字典项名称获取字典项类型
     *
     * @param name
     * @return
     */
    @ApiOperation(value = "根据字典项名称获取字典项类型", nickname = "根据字典项名称获取字典项类型")
    @GetMapping(value = "/getDictionaryTypeByName")
    ResponseData<DictionaryTypeResponse> getDictionaryTypeByName(@ApiParam(value = "name", required = true) @RequestParam(value = "name", required = true) String name) {
        return dictionaryQueryFeignApi.getDictionaryTypeByName(name);
    }

    /**
     * 根据Id查询字典项类型,包含字典项
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "根据Id查询字典项类型,包含字典项", nickname = "根据Id查询字典项类型,包含字典项")
    @GetMapping(value = "/getDictionaryTypeWithItemsById")
    ResponseData<DictionaryTypeWithItemResponse> getDictionaryTypeWithItemsById(@ApiParam(value = "id", required = true) @RequestParam(value = "id", required = true) Long id) {
        return dictionaryQueryFeignApi.getDictionaryTypeWithItemsById(id);
    }

    /**
     * 根据Type查询字典项类型,包含字典项
     *
     * @param type
     * @return
     */
    @ApiOperation(value = "根据Type查询字典项类型,包含字典项", nickname = "根据Type查询字典项类型,包含字典项")
    @GetMapping(value = "/getDictionaryTypeWithItemsByType")
    ResponseData<DictionaryTypeWithItemResponse> getDictionaryTypeWithItemsByType(@ApiParam(value = "type", required = true) @RequestParam(value = "type", required = true) String type) {
        return dictionaryQueryFeignApi.getDictionaryTypeWithItemsByType(type);
    }

    /**
     * 根据字典项名称获取字典项类型，包含字典项
     *
     * @param name
     * @return
     */
    @ApiOperation(value = "根据字典项名称获取字典项类型,包含字典项", nickname = "根据字典项名称获取字典项类型,包含字典项")
    @GetMapping(value = "/getDictionaryTypeWithItemsByName")
    ResponseData<DictionaryTypeWithItemResponse> getDictionaryTypeWithItemsByName(@ApiParam(value = "name", required = true) @RequestParam(value = "name", required = true) String name) {
        return dictionaryQueryFeignApi.getDictionaryTypeWithItemsByName(name);
    }

    /**
     * 根据Id获取字典项
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "根据Id获取字典项", nickname = "根据Id获取字典项")
    @GetMapping(value = "/getDictionaryItemById")
    ResponseData<DictionaryItemResponse> getDictionaryItemById(@ApiParam(value = "id", required = true) @RequestParam(value = "id", required = true) Long id) {
        return dictionaryQueryFeignApi.getDictionaryItemById(id);
    }

    /**
     * 根据字典项类型Id获取字典项
     *
     * @param typeId
     * @return
     */
    @ApiOperation(value = "根据字典项类型Id获取字典项", nickname = "根据字典项类型Id获取字典项")
    @GetMapping(value = "/getDictionaryItemsByTypeId")
    ResponseData<List<DictionaryItemResponse>> getDictionaryItemsByTypeId(@ApiParam(value = "typeId", required = true) @RequestParam(value = "typeId", required = true) Long typeId) {
        return dictionaryQueryFeignApi.getDictionaryItemsByTypeId(typeId);
    }
}
